package com.study.service.impl;

import com.study.dao.AppCategoryDao;
import com.study.dao.AppInfoDao;
import com.study.entity.AppCategory;
import com.study.entity.AppInfo;
import com.study.service.IAppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/10/18/018.
 */
@Service
public class AppInfoServiceImpl implements IAppInfoService {
    @Autowired
    private AppInfoDao appInfoDao;
    @Autowired
    private AppCategoryDao appCategoryDao;

    @Override
    public AppInfo findOneById(Integer id) {
        AppInfo appInfo = appInfoDao.findOneById(id);
        AppCategory appCategory1 = appCategoryDao.findOneById(appInfo.getCategoryLevel1());
        AppCategory appCategory2 = appCategoryDao.findOneById(appInfo.getCategoryLevel2());
        appInfo.setAppCategory1(appCategory1);
        appInfo.setAppCategory2(appCategory2);
        return appInfo;
    }

    @Override
    public List<AppInfo> findList(AppInfo appInfo) {
        return appInfoDao.findList(appInfo);
    }

    @Override
    public List<AppInfo> findList(AppInfo appInfo, Integer page, Integer size) {
        List<AppInfo> list = appInfoDao.findList(appInfo, page, size);
        for(AppInfo info:list){
            AppCategory appCategory1 = appCategoryDao.findOneById(info.getCategoryLevel1());
            AppCategory appCategory2 = appCategoryDao.findOneById(info.getCategoryLevel2());
            info.setAppCategory1(appCategory1);
            info.setAppCategory2(appCategory2);
        }
        return list;
    }

    @Override
    public void hitShelves(Integer appId) {
        appInfoDao.hitShelves(appId);
    }

    @Override
    public void offShelves(Integer appId) {
        appInfoDao.offShelves(appId);
    }

    @Override
    public int updateOne(AppInfo appInfo) {
        return appInfoDao.updateOne(appInfo);
    }

    @Override
    public int saveOne(AppInfo appInfo) {
        return appInfoDao.saveOne(appInfo);
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }

}
